﻿<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <link href="../../../Scripts/easyUI145/themes/color.css" rel="stylesheet" />
    <link href="../../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .style1 {
            width: 105px;
        }

        #Text4 {
            width: 447px;
        }

        #TB_Addr {
            width: 450px;
        }

        .panel-body-noborder {
            text-align: center;
        }

        #ulNodeFrmImp {
            list-style: none;
            padding: 0px;
        }

            #ulNodeFrmImp li {
                width: 100%;
                padding: 0px;
            }
    </style>
    <title>表单导入</title>
    <script language="JavaScript" src="../../../Comm/JScript.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../../Scripts/easyUI145/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../../Comm/Gener.js"></script>
    <script type="text/javascript" src="../../../Scripts/download.js"></script>
    <script type="text/javascript" language="javascript">

        closeWhileEscUp();

        //console.log(window.parent);

        //页面启动函数.
        var frmID = GetQueryString("FK_MapData");
        var flowNo = GetQueryString("FK_Flow");
        var nodeID = GetQueryString("FK_Node");

        var btnFrmLib = null;
        var selFrmNode = null;
        var Btn_Flows = null;
        $(function () {
            btnFrmLib = document.getElementById("btnFrmLib");
            selFrmNode = document.getElementById("selFrmNode");
            Btn_Flows = document.getElementById("Btn_Flows");
            if (nodeID == 0) {

                $("ul li:eq(1)").hide();
                $("ul li:eq(2)").hide();
            }
            else {
                $("ul li:eq(1)").show();
                $("ul li:eq(2)").show();
            }
            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            /*
            *  首先要把初始化控件的代码写入到这里,不然会导致界面的批量赋值失败.
            */

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("Imp_Init");

            if (data.indexOf("err@") > -1) {
                alert(data);
                return;
            }

            data = JSON.parse(data);

            //02.从节点表单导入
            var nodes = data["WF_Node"] || [];
            var ulHtml = '';
            for (var i = 0; i < nodes.length; i++) {
                var node = nodes[i];

                if (node.NodeID == nodeID)
                    continue;
                ulHtml += '<li><input id="nd' + node.NodeID + '" type="radio" name="node" class="btn btn-default" data-nodeid=' + node.NodeID + '><label for="nd' + node.NodeID + '">ID:' + node.NodeID + ' - ' + node.Name + '<label/></li>'
            }

            $('#ulNodeFrmImp').html(ulHtml);

            //03.从表单库导入
            var treedata = data["Sys_FormTree"];
            var rootdata = $.grep(treedata, function (item) {
                return item.ParentNo == "0";
            })[0];

            //构建树节点数据
            var root = {};
            root.text = rootdata.Name;
            root.state = "open";
            root.children = createJsonToTree(treedata, rootdata.No, data);


            //            $.grep(treedata, function (item) {
            //                //选出一级节点
            //                return item.ParentNo == rootdata.No;
            //            }).forEach(function (folder) {
            //                //构建node开始
            //                var node = {};
            //                node.text = folder.Name;
            //                node.state = "closed";
            //                node.children = [];
            //                $.grep(data["Sys_MapData"], function (map) {
            //                    //选出当前节点的二级节点
            //                    return map.FK_FormTree == folder.No;

            //                }).forEach(function (frm) {
            //                    node.children.push({
            //                        text: frm.Name,
            //                        id: frm.No
            //                    });
            //                });
            //                //构建node结束
            //                root.children.push(node);
            //            });

            $('#ulLib').tree({
                data: [root],
                onSelect: function (node) {
                    if (node.children == undefined) {
                        btnFrmLib.disabled = "";
                        selFrmNode.value = node.id;
                    } else {
                        btnFrmLib.disabled = "disabled";
                    }
                }
            });

            //04.从外部数据源导入
            var srcdata = data["SFDBSrcs"],
                tableHtml = "";

            tableHtml += "<table class='Table' cellSpacing='0' cellPadding='0'  border='0' style='width:100%'>";
            tableHtml += "<tr><td class='GroupTitle'>第1步：请选择数据源</td></tr>";
            tableHtml += "<tr><td valign='top' nowrap>";
            tableHtml += "<ul class='navlist'>";
            srcdata.forEach(function (item) {
                tableHtml += "<li><div><a href='javascript:GoToStep2(\"" + item.No + "\")'><span class='nav'>" + item.No + "  -  " + item.Name + "</span></a></div></li>";
            });
            tableHtml += "</ul>";
            tableHtml += "</td></tr>";
            tableHtml += "</table>";
            $("#srclayout").html(tableHtml);

            //05.从其他流程导入
            //            var treedata = data["WF_FlowSort"],
            //                        rootdata = $.grep(treedata, function (item) {
            //                            return item.ParentNo == "0";
            //                        })[0];
            //

            //            //构建树节点数据
            //            var root = {};
            //            root.text = rootdata.Name;
            //            root.state = "open";
            //            root.children = [];

            //            $.grep(treedata, function (item) {
            //                //选出一级节点
            //                return item.ParentNo == rootdata.No;
            //            }).forEach(function (folder) {
            //                //构建node开始
            //                var node = {};
            //                node.text = folder.Name;
            //                node.state = "closed";
            //                node.children = [];
            //                $.grep(data["WF_Flow"], function (map) {
            //                    //选出当前节点的二级节点
            //                    return map.FK_FlowSort == folder.No;

            //                }).forEach(function (frm) {
            //                    node.children.push({
            //                        text: frm.Name,
            //                        id: frm.No
            //                    });
            //                });
            //                //构建node结束
            //                root.children.push(node);
            //            });
            var treedata1 = data["WF_FlowSort"];
            var rootdata1 = $.grep(treedata1, function (item) {
                return item.ParentNo == "0";
            })[0];

            //构建树节点数据
            var root1 = {};
            treeJson = [];
            root1.text = rootdata1.Name;
            root1.state = "open";
            root1.children = createJsonToTree(treedata1, rootdata1.No, data, "Flow");

            $('#ul1').tree({
                data: [root1],
                onSelect: function (node) {
                    if (node.children == undefined) {
                        Btn_Flows.disabled = "";
                        $("#HD_FlowID").val(node.id);
                    } else {
                        Btn_Flows.disabled = "disabled";
                    }
                }
            });

            //加载完成.
            $("#Msg").html("");
        });

        //树形结构转换
        var treeJson = [];
        function createJsonToTree(treedata, parentNo, data, Type) {
            for (var i = 0; i < treedata.length; i++) {
                var folder = treedata[i];
                if (folder.ParentNo == parentNo) {
                    treeJson.push({
                        "id": folder.No,
                        "text": folder.Name,
                        "children": creatTreeChildern(treedata, folder.No, data, Type),
                        "state": "closed"
                    });
                }
            }
            function _(treeArray) {
                $.each(treeArray, function (i, o) {
                    if ($.isArray(o.nodes)) {
                        if (o.nodes.length == 0) {
                            o.nodes = undefined;
                        } else {
                            _(o.nodes);
                        }
                    }
                });
            }
            _(treeJson);
            return treeJson;
        }

        function creatTreeChildern(jsonArray, parentNo, data, Type) {
            var childList = []
            for (var i = 0; i < jsonArray.length; i++) {
                var folder = jsonArray[i];
                if (folder.ParentNo == parentNo) {
                    childList.push({
                        "id": folder.No,
                        "text": folder.Name,
                        "children": creatTreeChildern(jsonArray, folder.No, data, Type),
                        "state": "closed"
                    });
                }
            }
            if (Type == "Flow") {
                $.grep(data["WF_Flow"], function (map) {
                    //选出当前节点的二级节点
                    return map.FK_FlowSort == parentNo;

                }).forEach(function (frm) {
                    childList.push({
                        "text": frm.Name,
                        "id": frm.No
                    });
                });
            }
            else
                $.grep(data["Sys_MapData"], function (map) {
                    //选出当前节点的二级节点
                    return map.FK_FormTree == parentNo;

                }).forEach(function (frm) {
                    childList.push({
                        "text": frm.Name,
                        "id": frm.No
                    });
                });
            return childList;
        }
    </script>
    <script type="text/javascript">
        function addTab(title, url) {
            if ($('#tt').tabs('exists', title)) {
                $('#tt').tabs('select', title);
            } else {
                var content = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';
                $('#tt').tabs('add', {
                    title: title,
                    content: content,
                    closable: true
                });
            }
        }

        //从一个节点导入.
        function CopyFromNodeFrm() {

            var nodeIdSelected = $('#ulNodeFrmImp input:checked').data().nodeid;

            if (nodeIdSelected == null || nodeIdSelected == undefined) {
                alert('请选择一个节点');
                return;
            }

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp");

            handler.AddPara("FK_MapData", GetQueryString("FK_MapData"));
            handler.AddPara("FromFrmID", "ND" + nodeIdSelected);

            if ($('#CB_IsClear').attr('checked') == 'checked')
                handler.AddPara("IsClear", 1);
            else
                handler.AddPara("IsClear", 0);

            var val = document.getElementById("CB_IsSetReadonly").checked;
            if (val == true)
                handler.AddPara("IsSetReadonly", 1);
            else
                handler.AddPara("IsSetReadonly", 0);

            if (confirm('您确定要从[' + nodeIdSelected + ']执行导入吗？导入后会清空当前的设计的元素。') == false)
                return;

            var data = handler.DoMethodReturnString("Imp_FromsCopyFrm");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            alert(data + '\t\n 如果父页面不能刷新，请关闭当前表单设计器重新打开.');
            window.parent.location.href = window.parent.location.href;

        }

        //从xml文件导入
        function SaveImpFromLocalXML() {

            if (confirm('您确定要执行导入吗？导入后会清空当前的设计的元素。') == false)
                return;

            var formData = new FormData();
            var name = $("input").val();
            formData.append("file", $("#localXmlFile")[0].files[0]);
            formData.append("name", name);

            var doMethod = "Imp_LoadFrmTempleteFromLocalFile";
            var httpHandlerName = "BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp";
            $.ajax({
                url: dynamicHandler + "?DoType=HttpHandler&DoMethod=" + doMethod + "&HttpHandlerName=" + httpHandlerName + "&FK_MapData=" + frmID + "&FK_Node=" + GetQueryString("FK_Node") + "&FK_Flow=" + flowNo + "&m=" + Math.random(),
                type: 'POST',
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                data: formData,
                // 告诉jQuery不要去处理发送的数据
                processData: false,
                dataType: 'html',
                // 告诉jQuery不要去设置Content-Type请求头
                contentType: false,
                beforeSend: function () {

                },
                success: function (data) {

                    if (data.indexOf('err@') == 0) {
                        alert(data);
                        return;
                    }

                    alert(data + '\t\n 如果父页面不能刷新，请关闭当前表单设计器重新打开.');
                    window.parent.location.href = window.parent.location.href;
                },
                error: function (data) {
                    alert("系统错误:" + data);
                    return;
                }
            });

        }

        //从表单库导入
        function SaveImpFromLib() {
            var nodeId = selFrmNode.value;

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp");
            handler.AddPara("FK_MapData", frmID);
            handler.AddPara("FromFrmID", nodeId);
            handler.AddFormData();
            var data = handler.DoMethodReturnString("Imp_FromsCopyFrm");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            alert(data + '\t\n 如果父页面不能刷新，请关闭当前表单设计器重新打开.');
            window.parent.location.href = window.parent.location.href;

        }

        //从其他流程导入
        function SaveImpOtherFlow() {
            var flowNo = $("#HD_FlowID").val();
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp");
            handler.AddPara("FK_MapData", frmID);
            handler.AddPara("FK_Flow", flowNo);
            var data = handler.DoMethodReturnString("Imp_CopyFromFlow");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            alert(data + '\t\n如果父页面不能刷新，请关闭当前表单设计器重新打开.');
            window.parent.location.href = window.parent.location.href;
        }

    </script>
    <!--04.从外部数据源导入-->
    <script type="text/javascript">
        function doImpFromOutside() {
            var winWidth = 1050;
            var winHeight = 600;
            var iTop = (window.screen.height - 30 - winHeight) / 2; //获得窗口的垂直位置;
            var iLeft = (window.screen.width - 10 - winWidth) / 2; //获得窗口的水平位置;

            var url = "../ImpTableField.htm?FK_MapData=" + frmID + "&reset=true";
            //window.open(url);
            //return;

            window.open(url, "_blank", "height=" + winHeight + "px,width=" + winWidth + "px,top=" + iTop + ",left=" + iLeft + ",toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no");
        }
        function CheckAll(checked) {
            $.each($(":checkbox"), function () {
                this.checked = checked;
            });
        }

        //2.1 点击数据源，进入第二步
        function GoToStep2(FK_SFDBSrc) {
            hid_FK_SFDBSrc.value = FK_SFDBSrc;
            //hid_STable.value = GetQueryString("STable");
            //url: Handler + "?DoType=Imp_Src_Step2_Init&FK_MapData=" + frmID + "&FK_SFDBSrc=" + srcName + "&STable=" + GetQueryString("STable"),
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp");
            handler.AddPara("FK_SFDBSrc", FK_SFDBSrc);
            var data = handler.DoMethodReturnString("Imp_Src_Step2_Init");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            //转化成json.
            data = JSON.parse(data);
            $('#srclayout').html("");
            if (data) {
                $('#srclayout').layout({
                    height: 700,
                    fit: true
                });
                //1、左侧列表
                $('#srclayout').layout('add', {
                    region: 'west',
                    width: 200,
                    title: '选择 ' + FK_SFDBSrc + ' 数据表/视图',
                    split: true,
                });
                var table = data,
                    ul = '<ul class=\'ulcols\'>';
                table.forEach(function (item) {
                    ul += "<li><a id='" + item["NO"] + "' href='#' onclick=\"GetColumns('" + item["NO"] + "')\" >" + item["NAME"] + "</a></li>";
                });

                ul += '</ul>';
                $('#srclayout').layout('panel', 'west').append(ul);

                //2、右侧
                $('#srclayout').layout('add', {
                    region: 'center',
                    title: '第2步：请选择要导入的数据列（ ' + frmID + ' ）',
                    style: 'padding:5px;'
                });
                //填数据(只有个表头)
                Table_Cols(data);

            }

        }

        //2.2 点击表名获取表下的所有的列
        function GetColumns(tableName) {

            hid_STable.value = tableName;

            //1.样式处理。选中节点标红，其他节点去红
            var old = $(event.srcElement).css("color");
            $(".ulcols li a").css('color', old);
            $(event.srcElement).css('color', 'red');

            //2.获取数据 FK_MapData=ND18507&FK_SFDBSrc=NKApp&STable=ND104
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp");
            handler.AddPara("FK_SFDBSrc", hid_FK_SFDBSrc.value);
            handler.AddPara("FK_MapData", frmID);
            handler.AddPara("STable", tableName);
            var data = handler.DoMethodReturnString("Imp_Src_Step2_GetColumns");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            //转化成json.
            data = JSON.parse(data);
            Table_Cols(data);
        }

        //2.2.1 根据获取的数据，生成字段的table
        function Table_Cols(data) {

            var tr = "",
                tableHtml = "<table class='Table' cellpadding='2' cellspacing='2'>";
            tr += "<tr>";
            tr += "<td class='GroupTitle' nowrap=''>序</td>";
            tr += "<td class='GroupTitle' style='width:40px;text-align:center'><input id='CB_CheckAll' type='checkbox' name='CB_CheckAll' onclick='CheckAll(this.checked);'></td>";
            tr += "<td class='GroupTitle' nowrap=''>中文描述</td>";
            tr += "<td class='GroupTitle' style='width:80px;text-align:center'>类型</td>";
            tr += "<td class='GroupTitle' style='width:50px;text-align:center'>最大长度</td>";
            tr += "</tr>";

            tableHtml += tr;
            if (data.TableColumns) {
                var tableColumns = data.TableColumns;
                var attrs = data.MapAttrs;
                tableColumns.forEach(function (item, index) {

                    tr = "";
                    tr += "<tr>";
                    tr += "<td nowrap=''>" + item.colid + "</td>";
                    var disabletag = "";
                    if (attrs && attrs.length > 0) {
                        if ($.grep(attrs, function (attr) {
                            return attr.KeyOfEn == item.No;
                        }).length > 0) {
                            disabletag = "disabled";
                        }
                    }
                    tr += "<td><input " + disabletag + " id='CB_Col_" + item.No + "' type='checkbox' name='" + item.No + "' /><label for='CB_Col_" + item.No + "'>" + item.No + "</label></td>";
                    tr += "<td nowrap=''>" + item.Name + "</td>";
                    tr += "<td nowrap=''>" + item.DBType + "</td>";
                    tr += "<td class='TDNum'>" + item.DBLength + "</td>";
                    tr += "</tr>";
                    tableHtml += tr;
                });
            }
            tableHtml += "</table>";
            var $center = $('#srclayout').layout('panel', 'center');
            $center.html("").append(tableHtml);
            if (data.TableColumns) {
                var btnPrev = "<input type='button' id='btnPrev' value='上一步 ' />";
                var btnNext = "<input type='button' name='btnNext' value='下一步 ' onclick='Step3();' />";
                $center.append(btnPrev).append(btnNext);
            }
        }

        function Step3() {
            var chk_value = [];
            //获取所有选中的checkbox 字段用，拼接
            $('#srclayout input:checked').each(function () {
                chk_value.push(this.name);
            });

            var SColumns = chk_value.join();

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp");
            handler.AddPara("FK_SFDBSrc", hid_FK_SFDBSrc.value);
            handler.AddPara("FK_MapData", frmID);
            handler.AddPara("STable", hid_STable.value);
            handler.AddPara("SColumns", SColumns);
            var data = handler.DoMethodReturnString("Imp_Src_Step3_Init");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            //转化成json.
            data = JSON.parse(data);

            var tableHtml = "",
                impFields = "",
                Columns = data.COLUMNS,
                EnumsDataType = data.ENUMSDATATYPE,
                EnumsLGType = data.ENUMSLGTYPE,
                tr = "";

            var optionsEnumsLGType = "",
                optionsEnumsDataType;
            EnumsLGType.forEach(function (item) {
                optionsEnumsLGType += "<option value='" + item.INTKEY + "'>" + item.LAB + "</option>";
            });

            tableHtml += "<table class='Table' cellpadding='2' cellspacing='2'>";
            tableHtml += "<tr><td class='GroupTitle' nowrap=''>序</td>";
            tableHtml += "<td class='GroupTitle' nowrap=''>字段名</td>";
            tableHtml += "<td class='GroupTitle' nowrap=''>中文描述</td>";
            tableHtml += "<td class='GroupTitle' nowrap=''>数据类型</td>";
            tableHtml += "<td class='GroupTitle' nowrap=''>逻辑类型</td>";
            tableHtml += "<td class='GroupTitle' nowrap=''>绑定值(双击选择)</td>";
            tableHtml += "<td class='GroupTitle' nowrap=''>最大长度</td>";
            tableHtml += "<td class='GroupTitle' nowrap=''>顺序</td>";
            tableHtml += "</tr>";

            var dic = { "nvarchar": 1, "int": 2, "smallint": 2, "float": 3, "bit": 4, "double": 5, "date": 6, "datetime": 7, "money": 8 };

            if (Columns.length > 0) {
                Columns.forEach(function (item, index) {
                    tr = "";
                    tr += "<tr>";
                    tr += "<td class='Idx' nowrap=''>" + index + "</td>";
                    tr += "<td nowrap=''>" + item.NO + "</td>";
                    tr += "<td><input name='TB_Desc_" + item.NO + "' type='text' value='" + (item.NAME || item.NO) + "' size='20' id='TB_Desc_" + item.NO + "' /></td>";
                    tr += "<td><select name='DDL_DBType_" + item.NO + "' id='DDL_DBType_" + item.NO + "'>";
                    tr += _GetOptionsEnumsDataType(EnumsDataType, dic[item.DBTYPE]);
                    tr += "</select></td>";
                    tr += "<td><select name='DDL_LogicType_" + item.NO + "' id='DDL_LogicType_" + item.NO + "'>";
                    tr += optionsEnumsLGType;
                    tr += "</select></td>";
                    tr += "<td><input name='TB_BindKey_" + item.NO + "' type='text' size='30' id='TB_BindKey_" + item.NO + "' ondblclick='OpenSelectBindKey(this)' /></td>";
                    tr += "<td><input name='TB_Len_" + item.NO + "' type='text' value='" + item.DBLENGTH + "' size='5' id='TB_Len_" + item.NO + "' /></td>";
                    tr += "<td style='text-align:center' nowrap=''><a href='javascript:void(0)' onclick='up(this, 6)' class='easyui-linkbutton l-btn' data-options='iconCls:'icon-up'' group='' id=''><span class='l-btn-left'><span class='l-btn-text'><span class='l-btn-empty icon-up'>&nbsp;</span></span></span></a>&nbsp;<a href='javascript:void(0)' onclick='down(this, 6)' class='easyui-linkbutton l-btn' data-options='iconCls:'icon-down'' group='' id=''><span class='l-btn-left'><span class='l-btn-text'><span class='l-btn-empty icon-down'>&nbsp;</span></span></span></a>";
                    tr += "</td>";
                    tr += "</tr>";
                    tableHtml += tr;
                    impFields += item.NO + ","

                });
            }
            tableHtml += "</table>";

            $('#srclayout').html("").html(tableHtml);
            var hidImpFields = "<input type='hidden' id-'hidImpFields' name='hidImpFields' value='" + impFields + "' />";
            var btnNext = "<input type='button' name='btnNext' value='导入字段 生成表单 ' onclick='Save_Click();' />";
            var btnPrev = "<input type='button' id='btnPrev' value='上一步 ' />";
            $('#srclayout').append(hidImpFields).append(btnNext).append(btnPrev);
        }

        //构建 Options
        function _GetOptionsEnumsDataType(EnumsDataType, key) {
            var ret = "";
            EnumsDataType.forEach(function (item) {
                ret += "<option value='" + item.INTKEY + "' " + (item.INTKEY == key ? "selected" : "") + ">" + item.LAB + "</option>";
            });
            return ret;
        }

        //3、TODO导入字段 生成表单
        function Save_Click() {

            //hid_STable.value = tableName;
            var fromdata = $('#divCCForm').serialize()

            //2.获取数据 FK_MapData=ND18507     &FK_SFDBSrc=NKApp&STable=ND104
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner_ImpExp");
            handler.AddPara("FK_MapData", frmID);
            handler.AddFormData();
            var data = handler.DoMethodReturnString("Imp_Src_Step3_Save");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            //转化成json.
            data = JSON.parse(data);
            alert(data);

        }
        //导出表单模板
        function Down() {

            //var frmID = GetQueryString("FK_MapData");
            var md = new Entity("BP.Sys.MapData", frmID);

            //创建处理类.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_CCBPMDesigner");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("DownFormTemplete"); //执行方法，返回执行结果.

            if (data.indexOf('url@') == 0) {
                var url = data.replace('url@', '');
                window.location.href = url;
                return;
            }

            download(data, md.Name + ".xml", "xml");
            return;
        }

    </script>
</head>
<body>
    <form id="formCC" method="post" enctype="multipart/form-data">
        <div id="Msg">
        </div>
        <div id="tt" class="easyui-tabs" style="width: 100%; height: auto; padding: 0px;">
            <div title="从本机导入" style="">
                <div style="text-align: left; padding: 15px;">
                    <fieldset>
                        <legend>选择表单模板文件(*.xml),然后按确定按钮 </legend>
                        <ul>
                            <li>选择的模版文件必须是本机导出的，格式为 .xml 的文件. </li>
                        </ul>
                        <label style="padding-left: 8px;">
                        </label>
                        <br />
                        <br />
                        <input type="file" id="localXmlFile" name="localXmlFile" />
                        <input type="button" value="模板导入" onclick="SaveImpFromLocalXML()" />
                    </fieldset>
                </div>
            </div>

            <div title="从节点表单导入" id="divUlNodeFrmImp" style="padding: 15px; text-align: left">
                <fieldset>
                    <legend>请选择一个节点表单</legend>
                    <!-- 节点表单列表 -->
                    <ul id="ulNodeFrmImp">
                    </ul>
                    <hr />
                    <input type="checkbox" checked="checked" id="CB_IsClear" name="CB_IsClear" disabled="true" />
                    <label for="CB_IsClear">
                        是否清除现在已有的元素
                    </label>
                    <input type="checkbox" checked="checked" id="CB_IsSetReadonly" name="CB_IsSetReadonly" /><label for="CB_IsSetReadonly">是否只读</label>
                    <input type="button" value="执行从节点表单导入" onclick="CopyFromNodeFrm()" id="copyFromFrmNodeSave" />
                </fieldset>
            </div>
            <div title="从其他流程导入" id="div1" style="padding: 15px; text-align: left">
                <ul id="ul1" style="height: auto;">
                </ul>
                <input type="hidden" value="" id="HD_FlowID" name="HD_FlowID" />
                <input type="button" value="从其他流程导入" id="Btn_Flows" onclick="SaveImpOtherFlow()"
                       style="margin: 25px;" disabled="disabled" />
            </div>
            <div title="从表单库导入" id="divUlFrmTreeImp" style="padding: 15px; text-align: left">
                <ul id="ulLib" style="height: auto;">
                </ul>
                <input type="hidden" value="" id="selFrmNode" name="selFrmNode" />
                <input type="button" value="表单库导入" id="btnFrmLib" onclick="SaveImpFromLib()" style="margin: 25px;"
                       disabled="disabled" />
            </div>
            <div title="从外部数据源导入" style="padding: 15px; text-align: left">
                <div class="easyui-layout" style="height: 280px;">
                    <fieldset style="height: 90%;">
                        <legend id="help">导入字段生成表单</legend>
                        <ul>
                            <li>你可以选择多个数据源。</li>
                            <li>操作提示：指定内外部数据源中的一个已经设计好的表，把字段信息导入该表单</li>
                            <li>在自由表单里，双列排序，在傻瓜表单里，按照顺序排序。</li>
                        </ul>
                        <label style="padding-left: 8px;">
                        </label>
                        <input type="button" value="进入导入数据字段向导" onclick="doImpFromOutside()" style="margin-left: 40px;" />
                    </fieldset>
                    <!--<div id="divSrcImp" data-options="region:'center',title:'导入字段生成表单',fit:true" style="padding: 5px;">
                        <div id="srclayout">
                        </div>
                    </div>-->
                </div>
                <input type="hidden" id="hid_FK_SFDBSrc" name="hid_FK_SFDBSrc" value=" " />
                <input type="hidden" id="hid_STable" name="hid_STable" value=" " />
            </div>
            <div title="导出表单模板" style="">
                <div style="text-align: left; padding: 15px;">
                    <fieldset>
                        <legend>下载到本机 </legend>
                        <ul>
                            <li id="downli">驰骋工作流引擎已经为您生成了表单模版文件，<a href="javascript:Down();">请点击这里下载到本机</a></li>
                            <li>该xml格式的表单模版文件可以通过，软盘交换到其它ccbpm系统中去。</li>
                        </ul>
                    </fieldset>
                </div>
            </div>
        </div>
        <input type="hidden" name="hid_FK_MapData" value=" " />
        <input type="hidden" name="hid_FK_SFDBSrc" value=" " />
        <input type="hidden" name="hid_STable" value=" " />
    </form>
</body>
</html>
